import unittest
from common.functions import open_browser
from page.login_page import LoginEcshop
from page.index_page import IndexPage



class LoginTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = open_browser()
        # 创建loginpage对象
        cls.login = LoginEcshop(driver)
        cls.index = IndexPage(driver)

    def test_01_login(self):
        # 请求目标网址
        self.login.get('https://ecshop.test2.shopex123.com/user.php')
        # 登录操作
        self.login.input_username('fine1')
        self.login.input_userpassword('123456')
        self.login.remember()
        self.login.btn_login()
        # 断言登录成功
        username = self.index.fout_text(('class name', 'f4_b'))
        self.assertEqual('fine1', username)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.login.quit()

if __name__ == '__main__':
    unittest.main(verbosity=2)